import { HttpClient, HttpErrorResponse } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs/Observable";
/*
  Generated class for the HttpSeriveProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class HttpSeriveProvider {
  //公用的api地址
  api: string = "http://120.78.237.154/";

  constructor(public http: HttpClient) {
    console.log("Hello HttpSeriveProvider Provider");
  }

  get(url: string, options) {
    return this.http.get(url, options);
  }

  post(url: string, body?: any | null, options?: any) {
    return this.http.post(url, body, options);
  }

  put(url: string, body?: any, options?: any) {
    return this.http.put(url, body, options);
  }

  delete(url: string, option?: any) {
    return this.http.delete(url, option);
  }

  handleError(error: HttpErrorResponse) {
    if (error.error instanceof ErrorEvent) {
      console.log(error.error.message);
    } else {
      console.error(
        `error.status, ${error.status}`,
        `error.error, ${error.error}`
      );
    }
    return;
  }
}
